<?php
namespace app\mxty\model;
use think\Model;
use app\common\model\User;

class CourseLesson extends Model
{
    protected $table = 'athlon_course_lesson';
    protected $pk = 'lesson_id';

    public function students()
    {
      return $this->belongsToMany(User::class, CourseLessonClockIn::class, 'user_id', 'lesson_id');
    }

    public static function findLessons($course_id)
    {
      return self::where('course_id', $course_id)->select();
    }

    public function selectAllLessons($courseId)
    {
      return $this->with(['students', 'students.clockIn', 'students.avatar'])->where('course_id', $courseId)->order('sort asc')->select();
    }
}
